import java.util.Arrays;
import java.util.Comparator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-04-10
 * Time: 20:27
 */

//class Student implements Comparable<Student>{
//     public String name;
//     public int age;
//     public double score;
//
//    public Student(String name, int age, double score) {
//        this.name = name;
//        this.age = age;
//        this.score = score;
//    }
//
//    @Override
//    public String toString() {
//        return "Student{" +
//                "name='" + name + '\'' +
//                ", age=" + age +
//                ", score=" + score +
//                '}';
//    }
//
//    @Override
//    public int compareTo(Student o) {
//        return this.name.compareTo(o.name);
//    }
//
////    @Override
////    public int compareTo(Student o) {
////        return this.age - o.age;
////    }
//}
class Student{
    public String name;
    public int age;
    public double score;

    public Student(String name, int age, double score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }

}

class AgeComparator implements Comparator<Student> {

    @Override
    public int compare(Student o1, Student o2) {
        return o1.age - o2.age;
    }
}

class NameComparator implements Comparator<Student> {

    @Override
    public int compare(Student o1, Student o2) {
        return o1.name.compareTo(o2.name);
    }
}

class ScoreComparator implements Comparator<Student> {

    @Override
    public int compare(Student o1, Student o2) {
        return (int)(o1.score - o2.score);
    }
}


public class TestDemo {

    public static void main(String[] args) {
        Student[] student = new Student[3];
        student[2] = new Student("张三",18,88.9);
        student[0] = new Student("李四",89,98.9);
        student[1] = new Student("王二麻子",78,38.9);
        AgeComparator ageComparator = new AgeComparator();
        System.out.println(Arrays.toString(student));
        Arrays.sort(student,ageComparator);
        System.out.println(Arrays.toString(student));
    }

}
